﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LynxWikiScripting;
using LynxWiki.DomainModel;
using LynxWiki.Search;

namespace LynxWiki.Controllers
{
    public class RunScriptController : Controller
    {
        //
        // GET: /RunScript/

        public ActionResult Index()
        {
            ViewBag.TagCloud = new TagCloud(LuceneSearch.GetTagCount());
            ViewBag.Result = "";
            return View();
        }

        [HttpPost]
        public ActionResult Index(FormCollection fc)
        {
            ViewBag.TagCloud = new TagCloud(LuceneSearch.GetTagCount());
            string result = WikiScriptEngine.ExecuteBehavior(fc["txtScript"]);
            result = result.Replace("<", "&lt;");
            ViewBag.Result = result.Replace("\r\n", "<br />");
            ViewBag.Script = fc["txtScript"];
            return View();
        }

    }
}
